package com.snap.vseries.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.LinearLayout;

import com.snap.vseries.R;
import com.snap.vseries.adapter.TemplateAddAdapter;
import com.snap.vseries.base.BaseActivity;
import com.snap.vseries.bean.ExpEntity;
import com.snap.vseries.model.DBManager;
import com.snap.vseries.utils.TopTitleUtils;

import org.litepal.crud.callback.FindMultiCallback;

import java.util.List;

import butterknife.BindView;

/**
 * 远程项目展示
 * 1、通过开关控制是否显示到本地
 *
 * @author Rachel
 */
public class TemplatesAddActivity extends BaseActivity {
    @BindView(R.id.container)
    RecyclerView container;
    private TemplateAddAdapter adapter;

    @Override
    protected int layoutResId() {
        return R.layout.activity_templates_add;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
        initView();
    }

    private void initData() {
        adapter = new TemplateAddAdapter(this, null);
        container.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        container.setLayoutManager(new LinearLayoutManager(this, LinearLayout.VERTICAL, false));
        container.setAdapter(adapter);
        notifyTemplateList();

    }

    private void notifyTemplateList() {
        DBManager.get().getTemplateList(new FindMultiCallback<ExpEntity>() {
            @Override
            public void onFinish(List<ExpEntity> list) {
                adapter.updateData(list);
            }
        });
    }

    private void initView() {
        new TopTitleUtils(this).setTitle("添加项目");
    }
}
